<@pp.dropOutputFile/>
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<#assign package = package + "/" + doc.artifactid?replace(".", "/")>
<#assign package = package + "/" + table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name="/main/java/" + package + "/dao/" + fileName + "DaoOracleImpl.java"/>
/*
 * File name : ${fileName}DaoOracleImpl.java ${doc.date}
 * Copyright ${doc.copyright}. All rights reserved.
 */
package ${package?replace("/", ".")}.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapClient;
import ${package?replace("/", ".")}.domain.${fileName};
import com.xust.common.Outcome;

public class ${fileName}DaoOracleImpl extends SqlMapClientDaoSupport implements ${fileName}Dao
{
	private static final String prefix = "${fileName?uncap_first}";
	private Log log = LogFactoryImpl.getLog(${fileName}DaoOracleImpl.class);
	
	public Outcome create(${fileName} newValue){
		Outcome res = new Outcome();
		try{
			Integer id = (Integer)getSqlMapClientTemplate().insert(prefix + ".create", newValue);
			if(null != id && id > 0){
				res.setResult(0);
				res.setMsg("create.success");
				newValue.set<#if table.idFieldName??>${table.idFieldName?cap_first}<#else>Id</#if>(id);
				res.setData(newValue);
			}else{
				res.setMsg("create.fail");
			}
		}catch(Exception e){
			res.setMsg("create.fail");
			res.setDetail(e.getMessage());
			log.info(e.getMessage());
		}
		return res;
	}

	public Outcome get(Integer id) {
		Outcome result = new Outcome();
		try{
			List<${fileName}> objs = (List<${fileName}>)getSqlMapClientTemplate().queryForList(prefix + ".get", id);
			if(null != objs && objs.size() > 0){
				List<${table.name}> data = new ArrayList<${table.name}>();
				data.add(objs.get(0));
				result.setResult(0);
				result.setMsg("find.success");
				result.setData(data);
			}else{
				result.setMsg("find.fail");
			}
		}catch(Exception e){
			result.setMsg("find.fail");
			result.setDetail(e.getMessage());
			log.info(e.getMessage());
		}
		return result;
	}
	
	public Outcome size(Map<String, Object> params) {
		Outcome result = new Outcome();
		try{
			Integer rows = (Integer)getSqlMapClientTemplate().queryForObject(prefix + ".size", params);
			if(null != rows){
				result.setResult(0);
				result.setMsg("find.success");
				result.setData(rows);
			}else{
				result.setMsg("find.fail");
			}
		}catch(Exception e){
			result.setMsg("find.fail");
			result.setDetail(e.getMessage());
			log.info(e.getMessage());
		}
		return result;
	}
	
	public Outcome getPage(Map<String, Object> params){
		Outcome result = new Outcome();
		try{
			List<${fileName}> objs = (List<${fileName}>)getSqlMapClientTemplate().queryForList(prefix + ".getPage", params);
			if(null != objs){
				result.setResult(0);
				result.setMsg("find.success");
				result.setData(objs);
			}else{
				result.setMsg("find.fail");
			}
		}catch(Exception e){
			result.setMsg("find.fail");
			result.setDetail(e.getMessage());
			log.info(e.getMessage());
		}		
		return result;
	}

	public Outcome update(${fileName} newValue){
		Outcome res = new Outcome();
		try{
			Integer rows_effected = getSqlMapClientTemplate().update(prefix + ".update", newValue);
			if(null != rows_effected){
				res.setResult(0);
				res.setMsg("update.success");
				res.setData(newValue);
			}else{
				res.setMsg("update.fail");
			}
		}catch(Exception e){
			res.setMsg("update.fail");
			res.setDetail(e.getMessage());
			log.info(e.getMessage());
		}
		return res;
	}

	public Outcome deleteItems(List<Integer> ids){
		Outcome res = new Outcome();
		try{
			Integer rows_effected = getSqlMapClientTemplate().delete(prefix + ".deleteItems", ids);
			if(null != rows_effected){
				res.setResult(0);
				res.setMsg("update.success");
				res.setData(rows_effected);
			}else{
				res.setMsg("update.fail");
			}
		}catch(Exception e){
			res.setMsg("update.fail");
			res.setDetail(e.getMessage());
			log.info(e.getMessage());
		}
		return res;
	}
	
	public Outcome deleteAll(){
		Outcome res = new Outcome();
		try{
			Integer rows_effected = getSqlMapClientTemplate().delete(prefix + ".deleteAll", null);
			if(null != rows_effected){
				res.setResult(0);
				res.setMsg("update.success");
				res.setData(rows_effected);
			}else{
				res.setMsg("update.fail");
			}
		}catch(Exception e){
			res.setMsg("update.fail");
			res.setDetail(e.getMessage());
			log.info(e.getMessage());
		}
		return res;
	}
}
</#list>